package com.office.file.message.service.impl;

import java.util.List;
import com.office.common.utils.DateUtils;
import com.office.common.utils.SecurityUtils;
import com.office.file.category.domain.FileCategory;
import com.office.file.category.service.IFileCategoryService;
import com.office.file.message.service.IFileInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.office.file.message.mapper.FileInfoMapper;
import com.office.file.message.domain.FileInfo;
import org.springframework.transaction.annotation.Transactional;

import static com.office.common.utils.SecurityUtils.*;

/**
 * 文件信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-05-22
 */
@Service

public class FileInfoServiceImpl implements IFileInfoService
{
    @Autowired
    private FileInfoMapper fileInfoMapper;


    /**
     * 查询文件信息
     * 
     * @param fileId 文件信息主键
     * @return 文件信息
     */
    @Override
    public FileInfo selectFileInfoByFileId(Long fileId)
    {
        return fileInfoMapper.selectFileInfoByFileId(fileId);
    }

    /**
     * 查询文件信息列表
     * 
     * @param fileInfo 文件信息
     * @return 文件信息
     */
    @Override
    public List<FileInfo> selectFileInfoList(FileInfo fileInfo)
    {
        System.out.println(fileInfo);
        return fileInfoMapper.selectFileInfoList(fileInfo);
    }

    /**
     * 新增文件信息
     * 
     * @param fileInfo 文件信息
     * @return 结果
     */
    @Override
    public int insertFileInfo(FileInfo fileInfo)
    {
        fileInfo.setUploadTime(DateUtils.getNowDate());
        fileInfo.setUserId(getUserId());
        fileInfo.setUpdateTime(DateUtils.getNowDate());
        return fileInfoMapper.insertFileInfo(fileInfo);
    }

    /**
     * 修改文件信息
     * 
     * @param fileInfo 文件信息
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int updateFileInfo(FileInfo fileInfo)
    {
        fileInfo.setUpdateTime(DateUtils.getNowDate());
        fileInfo.setUserId(getUserId());
        int i = fileInfoMapper.updateFileInfo(fileInfo);

//        FileCategory fileCategory = new FileCategory();
//        fileCategory.setCategoryId(fileInfo.getCategoryId());
//        fileCategory.setCategoryName(fileInfo.getCategoryName());
//        fileCategory.setFileId(fileInfo.getFileId());
//        updateFileCategoryName(fileCategory);

        return i;
    }

//    //修改文件分类
//    @Override
//    public int updateFileCategoryName(FileCategory fileCategory) {
//        return fileInfoMapper.updateFileCategoryName(fileCategory);
//    }

    /**
     * 批量删除文件信息
     * 
     * @param fileIds 需要删除的文件信息主键
     * @return 结果
     */
    @Override
    public int deleteFileInfoByFileIds(Long[] fileIds)
    {
        return fileInfoMapper.deleteFileInfoByFileIds(fileIds);
    }

    /**
     * 删除文件信息信息
     * 
     * @param fileId 文件信息主键
     * @return 结果
     */
    @Override
    public int deleteFileInfoByFileId(Long fileId)
    {
        return fileInfoMapper.deleteFileInfoByFileId(fileId);
    }

    /**
     * 获取下拉分类名
     * @return
     */
    @Override
    public List<FileCategory> getCategoryName() {
        return fileInfoMapper.getCategoryName();
    }
}
